<script type="text/javascript" src="../jquery/js/jquery-1.8.3.js" ></script>
<script type="text/javascript" src="../jquery/js/jquery-ui.js" ></script>

<?php

	require_once(dirname(__FILE__)."/../core/safeParam.php");

	if(isset($_GET['rid'])){
		$rid = $_GET['rid'];
	}
	
	if($_SESSION['admin'] == 1){
  		echo '
		<script>
  			function mostrarControl(){
  				document.getElementById("configPrincipal").style.display = "none";
  				document.getElementById("configEmail").style.display = "none";
  				document.getElementById("configControls").style.display = "block";
  				document.getElementById("configSeguridad").style.display = "none";
  			}
  			
			function mostrarPermisos(){
  				document.getElementById("configSeguridad").style.display = "block";
  			}
  		</script>
  		';
	}
	
	if (!isset($_GET['rid']) && $_SESSION['admin'] == 1 && (!isset($_SESSION['staffUser']))) {	
		$results = $database->select("SELECT * FROM config ORDER by id ");
		
		echo '
		<div class="tituloOpcionesAdmin">
			<img src="images/icons/cog_edit.png" />
			Configuración Principal
		</div>
		
		<div class="opcionesOpcionesAdmin">
			<a href="index.php?edit=config&action=add&rid=0">
				<img src="add.png" border="0">&nbsp;&nbsp;Agregar Delivery
			</a>
		</div>	
		
		<br />
			
		<table cellspacing="2" cellpadding="2" border="0" class="table">
			<tr>
				<th width="10%"><p align="center">ID</p></th>
				<th width="70%"><p align="center">Nombre del sitio</p></th>
				<th width="20%"><p align="center">Funciones</p></th>
      	</tr>';
      
      if ($results != false) {
      	for ($i = 0; $i < count($results); $i++) {
      		echo '
      		<tr>
      			<td>
      				' . $results[$i]['id'] . '
      			</td>
      			
      			<td>
      				<a href="index.php?edit=config&rid=' . $results[$i]['id'] . '">
      					' . $results[$i]['sitename'] . '
      				</a>
      			</td>
      			
      			<td>
      				<a href="index.php?edit=config&rid=' . $results[$i]['id'] . '">
      					<img src="application_edit.png"  border="0">Editar
      				</a>';
      		
      		if ($results[$i]['id'] != 1) {
      			echo '
      				<br />
      				
      				<a href="../functions/menus.php?function=delete-config&id=' . $results[$i]['id'] . '">
	        				<img src="delete.png"  border="0">Eliminar
        				</a>';
      			}
      			
      			echo '
      			</td> 
      		</tr>';
    		}
  		}
  		
  		echo '
	  		</table>	';
  	} else {
		// administering one restaurant 
		if ($_SESSION['admin'] != 1) {
			// session variable overrides get parameter
			$rid = $_SESSION['admin'];
  		} 
  		
  		if ($rid != 0) {
  			$query   = $database->query("SELECT * FROM config where id = " . $rid . "  ");
  			$results = mysql_fetch_array($query);
    		$open           = openTime($results['hours'], 'open');
    		$closed         = openTime($results['hours'], 'close');
    		$blackout_start = openTime($results['hours'], 'blackout_start');
    		$blackout_end   = openTime($results['hours'], 'blackout_end');
  		}
?>


<div class="tituloOpcionesAdmin">	
	<img src="images/icons/cog_edit.png" />
	Configuración Principal
</div>

<div class="configurarBusqueda">
  <h3>Configuraración de búsqueda</h3>
  	
  	<div class="configurarBusquedaBarrio">
  	  	<a href="#" onclick="mostrarBusquedaBarrio()">
  			Busqueda por Barrio
  		</a>
  		
  		<div id="contBusqBarrio" class="contenidoConfigurarBusquedaBarrio">
  			<?php require_once(dirname(__FILE__)."/config_areas.php"); ?>
  		</div>
  	</div>
</div>


<div class="configurarBusqueda">
	<h3>Configuración del Local</h3>
	
	<?php
  		if($_SESSION['admin'] == 1){
  			echo '
  			<div class="navConfiguracionPrincipal">
				<a onclick="mostrarPrincipal();">
  					Principal
  				</a>
  					
				<a onclick="mostrarControl();">
  					Control
  				</a>
  			</div>';
    	}
   ?>		
		
	<div class="contenidoConfiguracionPrincipal">
	
		<div id="configPrincipal" class="divConfiguracionPrincipal">
			<?php
				include 'config_main.php';
			?>
		</div>
		
		<?php
  			if($_SESSION['admin'] == 1){
  				echo '
  					<div id="configControls" class="divConfigurarControl">';
  						include "config_controls.php";
  				echo '
  					</div>
  				';
   		}
   	?>
	</div>
</div>
<?php
}
?>

<script type="text/javascript" >
	function mostrarBusquedaBarrio(){
		$("#contBusqBarrio").toggle(500);
	}
	
	function mostrarPrincipal(){
		$("#configControls").hide();
		$("#configPrincipal").show(200);
	}
	
	function mostrarControl(){
		$("#configControls").show(200);
		$("#configPrincipal").hide();
	}
</script>
